package com.enqualcomm.kids.mvp.seetheworld;

import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.enqualcomm.kids.R;
import com.facebook.drawee.view.SimpleDraweeView;

import java.util.List;

import common.utils.MyLogger;

/**
 * Created by Sunzhigang on 2016/3/11.
 */
public class AQYListViewAdapter extends BaseAdapter {

    private List<AQYAlbum.Album> albumList;
    private Context context;

    public void setData(List<AQYAlbum.Album> albumList) {
        this.albumList = albumList;
        notifyDataSetChanged();
    }

    public AQYListViewAdapter(Context context) {
        this.context = context;
    }

    @Override
    public int getCount() {
        return albumList != null ? albumList.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return albumList != null ? albumList.get(position) : null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.aqi_gridview_item, null);
            holder.album_iv = (SimpleDraweeView) convertView.findViewById(R.id.image_view);
            holder.album_title_tv = (TextView) convertView.findViewById(R.id.gv_title_tv);
            holder.album_describe_tv = (TextView) convertView.findViewById(R.id.set_tv);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

//        Uri uri = Uri.parse(albumList.get(position).picUrl);
//        holder.album_iv.setImageURI(uri);
//        AQYAlbum.Album album = albumList.get(position);
//        holder.album_title_tv.setText(albumList.get(position).albumName);
//        holder.album_describe_tv.setText(albumList.get(position).focus);
//        convertView.setSelected(false);
        String imageurl = albumList.get(position).posterPicUrl;
//        MyLogger.kLog().i("posterPicUrl:"+imageurl);
        if (imageurl != null) {
            Uri uri = Uri.parse(imageurl);
            holder.album_iv.setImageURI(uri);
        }

//        AQYAlbum.Album album = albumList.get(position);
//        MyLogger.kLog().i(albumList.get(position).data.tvName);

        holder.album_title_tv.setText(albumList.get(position).albumName);
        holder.album_describe_tv.setText("第"+albumList.get(position).tvYear+"期");
//        convertView.setSelected(false);
        return convertView;
    }

    static class ViewHolder {
        SimpleDraweeView album_iv;
        TextView album_title_tv;
        TextView album_describe_tv;
    }
}
